package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.domain.Dish;
import com.itheima.domain.vo.DishVo;
import com.itheima.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dish")
public class DishController {


    @Autowired
    private DishService dishService;





    @PostMapping
    public R<String> dishSave(@RequestBody DishVo dishVo) {
        log.info("新增菜品信息：{}", dishVo.toString());
        return dishService.adminDishSave(dishVo);
    }

    /**
     * 分页查询
     * @param name 模糊查询名称
     * @param page 第几页
     * @param pageSize 每页最大显示数
     * @return 查询出的数据
     */
    @GetMapping("/page")
    public R<Page<Dish>> pageselect(@RequestParam(value = "name",required = false)String name, @RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        log.info("page={},pageSize={},name={}", page, pageSize, name);
        return  dishService.adminPageSelect(name,page,pageSize);
    }

   @GetMapping("/{id}")
   public R<DishVo> selectById(@PathVariable String id){
       log.info("查询菜品id：{}",id);
       return dishService.adminSelectDishById(id);
   }

   @PutMapping
   public R<String> updateDish(@RequestBody DishVo dishVo){
       log.info("修改菜品信息：{}",dishVo);
       return  dishService.adminUpdateDish(dishVo);

   }

    @DeleteMapping
    public R<String> dishDelete(@RequestParam("ids") List<String> ids){
        log.info("删除菜品信息：{}",ids);
        return dishService.adminDishDelete(ids);
    }

    @PostMapping("/status/{status}")
    public R<String> dishStatus(@RequestParam("ids") List<String> ids,@PathVariable Integer status){
        log.info("启用或禁用菜品信息：{}",ids);
        return dishService.adminDishStatus(ids,status);

    }


    @GetMapping("/list")
    public R<List<Dish>> categoryList( @RequestParam(value = "categoryId" ,required = false) String categoryId,@RequestParam(value = "name",required = false) String name ){
        log.info("查询菜品集合：categoryId={},name={}",categoryId,name);
        return dishService.adminCategoryList(categoryId,name);
    }


   }



















